package com.company.calendar.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.calendar.entity.DateType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 日期类型Mapper接口
 * 
 * @author System
 * @since 1.0.0
 */
@Mapper
public interface DateTypeMapper extends BaseMapper<DateType> {
    
    /**
     * 根据公司ID查找所有日期类型
     */
    @Select("SELECT * FROM date_types WHERE company_id = #{companyId} AND is_deleted = 0")
    List<DateType> findByCompanyIdAndIsDeletedFalse(@Param("companyId") Long companyId);
    
    /**
     * 根据公司ID和类型编码查找
     */
    @Select("SELECT * FROM date_types WHERE company_id = #{companyId} AND type_code = #{typeCode} AND is_deleted = 0")
    DateType findByCompanyIdAndTypeCodeAndIsDeletedFalse(@Param("companyId") Long companyId, 
                                                        @Param("typeCode") String typeCode);
    
    /**
     * 检查类型编码是否存在
     */
    @Select("SELECT COUNT(*) FROM date_types WHERE company_id = #{companyId} AND type_code = #{typeCode} AND is_deleted = 0")
    int existsByCompanyIdAndTypeCodeAndIsDeletedFalse(@Param("companyId") Long companyId, 
                                                      @Param("typeCode") String typeCode);
}
